package com.atguigu.realtime.util

import org.apache.spark.sql.{Encoder, SparkSession}

/**
 * Author atguigu
 * Date 2020/11/17 10:27
 */
object SparkSqlUtil {
    val url = "jdbc:phoenix:hadoop162,hadoop163,hadoop164:2181"
    
    // 从spark-sql读取的数据, 转成rdd
    def getRDD[T: Encoder](spark: SparkSession, sql: String) = {
        spark
            .read
            .format("jdbc")
            .option("url", url)
            .option("query", sql)
            .load()
            .as[T]
            .rdd
    }
}
